<?php
namespace zzymessage;

class Message
{
	private $id = 'tjwangwei';//账号
	private $pwd = 'jucheng16';//密码
	
	/**
	* 发送短信 2017-10-15
	* @param $tos 手机号  $content  内容
	*/
	function sendmessage($tos,$content,$attach = array()){
		$url = "http://service.winic.org:8009/sys_port/gateway/index.asp?";
		$data = "id=%s&pwd=%s&to=%s&content=%s&time=";
		$id = $this -> id;//账号
		$pwd = $this -> pwd;//密码
		$to = $tos;
		
		$contents = urlencode(iconv("UTF-8","GB2312",$content));
		$rdata = sprintf($data, $id, $pwd, $to, $contents);
			
		$ch = curl_init();
		curl_setopt($ch, CURLOPT_POST,1);
		curl_setopt($ch, CURLOPT_POSTFIELDS,$rdata);
		curl_setopt($ch, CURLOPT_URL,$url);
		curl_setopt($ch,CURLOPT_RETURNTRANSFER,TRUE);
		//打印一下参数 可以看到 在GB2312编码模式的浏览器下 显示字符是正常的
		$result = curl_exec($ch);
		curl_close($ch);
		
		!isset($attach['uid']) && $attach['uid'] = 0;
		apilog($attach['uid'], 'zzymessage', 'sendmessage', $url, $rdata, $result);
		
		$result = substr($result,0,3);
		return $result;
	}
	
	/**
	* 查询短信余额	 2017-10-15
    */
	public function restmoney(){
		$url = "http://service.winic.org:8009/webservice/public/remoney.asp";
		$data = "id=%s&pwd=%s&to=%s&content=%s&time=";
		$id = $this -> id;//账号
		$pwd = $this -> pwd;//密码
		$data = "uid=%s&pwd=%s";
		$rdata = sprintf($data, $id, $pwd);
		
		$ch = curl_init();
		curl_setopt($ch, CURLOPT_POST,1);
		curl_setopt($ch, CURLOPT_POSTFIELDS,$rdata);
		curl_setopt($ch, CURLOPT_URL,$url);
		curl_setopt($ch,CURLOPT_RETURNTRANSFER,TRUE);
		//打印一下参数 可以看到 在GB2312编码模式的浏览器下 显示字符是正常的
		$result = curl_exec($ch);
		curl_close($ch);
		return $result;
	}
}